﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using PatternWell.PAC.SL;
using PatternWell.PAC;
namespace $rootnamespace$
{
    public partial class $safeitemname$
    {
        #region Logging Helper

        /// <summary>
        /// Partial helper method that will capture an exception and make it avaliable for logging.
        /// </summary>
        /// <param name="exception">The source exception that has occured.</param>
        /// <param name="methodQualifiedName">The fully qualified name of the method where the exception was caught.</param>
        partial void LogContractError(System.Exception exception, string methodQualifiedName);

        #endregion

        #region Dispose Implementation - Implementation of the disposal helper method (Do not modify)

        /// <summary>
        /// Helper method that releases resources for this class implementation.
        /// </summary>
        /// <param name="disposed">flag that determines if the class has already been disposed.</param>
        protected override void Dispose(bool disposed)
        {
            try
            {
                ReleaseResourcesFor$safeitemname$();
                base.Dispose(disposed);
            }
            catch(System.Exception disposeError)
            {
                LogContractError(disposeError, "$rootnamespace$.$safeitemname$.Dispose");
            }
        }

        #endregion

        #region Release Management - Logic used to release resources for this class (Add release logic in the supplied helper methods)

        /// <summary>
        /// Helper method that releases resource for the '$safeitemname$' class.
        /// </summary>
        private void ReleaseResourcesFor$safeitemname$()
        {
            try
            {
                //Helper method will be executed if the partial method has been implemented. Otherwise it will be removed from the compile step.
                ReleasePACResources();

                ReleasePACContract();
            }
            catch(System.Exception releaseError)
            {
                LogContractError(releaseError, "$rootnamespace$.$safeitemname$.ReleaseResourcesFor$safeitemname$");
            }
        }

        /// <summary>
        /// Helper method that gets called before the PAC contract resources are released.
        /// </summary>
        partial void ReleasePACResources();

        #endregion

        #region PAC Contract Initialization

        public override void InitializePac()
        {
            try
            {
                base.InitializePac();

                //TODO:$safeitemname$ - InitializePAC
                //Initialize all pac contract items here
            }
            catch(System.Exception initializeError)
            {
                LogContractError(initializeError, "$rootnamespace$.$safeitemname$.InitializePac");
            }
        }

        #endregion

        #region PAC Contract Release

        /// <summary>
        /// Helper method that releases all the resources in the pac contract.
        /// </summary>
        private void ReleasePACContract()
        {
            try
            {
                //Helper method will be executed if the partial method has been implemented. Otherwise it will be removed from the compile step.
                CleanupController();

                //TODO:$safeitemname$ - ReleasePACContract
                //Release all contract properties
                //Release all contract events

            }
            catch(System.Exception releaseError)
            {
                LogContractError(releaseError, "$rootnamespace$.$safeitemname$.ReleasePACContract");
            }
        }

        /// <summary>
        /// Helper method that runs additional release logic for the contract that is not related to the PAC contract. 
        /// </summary>
        partial void CleanupController();

        #endregion

        #region PAC Contract

        //TODO:$safeitemname$ - Implement PAC contract
        //Implement pac contract items here

        #endregion

        #region Child PACs

        //TODO:$safeitemname$ - Implement Child PAC's here 
        //Implement logic to host child pac implementations here
        //
        #endregion


    }
}
